<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Conf\ConfModel;

use Srv\Libs\Frame\Conf;

final class PayGooglePayConfGroup
{
    private array $PayGooglePayConfGroupNameList        = [];       // PayGooglePayConf List groupName

    /**
     * @return array
     * getGroupNameList
     */
    public function getGroupNameList():array
    {
        $PayGooglePayConfList           = [];
        $groupNameList                  = Conf::getGroupNameList(PayGooglePayConf::PREFIX);
        if(count($groupNameList) < 1) return $PayGooglePayConfList;
        foreach ($groupNameList as $groupName){
            $PayGooglePayConf           = $this->getByGroupName($groupName);
            if($PayGooglePayConf instanceof PayGooglePayConf) $PayGooglePayConfList[$groupName] = $PayGooglePayConf;
        }
        return $PayGooglePayConfList;
    }

    /**
     * @param string $groupName
     * @return PayGooglePayConf|null
     * getByGroupName
     */
    public function getByGroupName(string $groupName):?PayGooglePayConf
    {
        if(strlen($groupName) < 1) return null;
        if(isset($this->PayGooglePayConfGroupNameList[$groupName]) && $this->PayGooglePayConfGroupNameList[$groupName] instanceof PayGooglePayConf) return $this->PayGooglePayConfGroupNameList[$groupName];
        $confData                                           = Conf::getGroupList(PayGooglePayConf::PREFIX.$groupName.'.', false, true);
        if(count($confData) < 1) return null;
        $this->PayGooglePayConfGroupNameList[$groupName]    = new PayGooglePayConf($confData, $groupName);
        return $this->PayGooglePayConfGroupNameList[$groupName];
    }
}